// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db = cloud.database();
const _ = db.command;
// 云函数入口函数
exports.main = async (event, context) => {
  const openid = cloud.getWXContext().OPENID
  var {carArr} = event;
  for(var i=0;i<carArr.length;i++)
  {
   await db.collection("xcmall_product").where({
      _id:carArr[i].goodid
    }).update({
      data:{
        stock:_.inc(-carArr[i].num),
        sales:_.inc(carArr[i].num)
      }
    })
  }
      return {msg:"修改成功",code:1111}
}